using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace InventorySystem
{
    public class Box : MonoBehaviour, Iinteractable
    {

        private SpriteRenderer spriteRenderer;
        public Sprite openBox;
        public Sprite closeBox;
        private GameItemSpawnerController gameItemSpawnerController;   

        public bool isDone;

        private void Awake()
        {
            spriteRenderer = GetComponent<SpriteRenderer>();
        }

        private void OnEnable()
        {
            spriteRenderer.sprite = isDone ? openBox : closeBox;
            gameItemSpawnerController = GetComponent<GameItemSpawnerController>();
        }

        public void TriggerAction()
        {
            if (!isDone)
            {
                OpenBox();
                gameItemSpawnerController.OpenBox();

            }
        }

        public void OpenBox()
        {
            spriteRenderer.sprite = openBox;
            isDone = true;
            gameObject.tag = "Untagged";
        }

    }
}